package com.ftx.controller.test.thread;

/**
 * Created by fengtingxin on 2020/12/1 8:09 下午
 */
public class ThreadTestA {

    public static void methodA(){
        System.out.println("start methodA");
        try{
            Thread.sleep(10000);
        }catch (Exception e){

        }
        System.out.println("start methodA");
    }

    public synchronized void methodB(){
        System.out.println("end methodB");
    }

    public static void main(String[] args) {
        ThreadTestA threadTestA = new ThreadTestA();
        ThreadA threadA = new ThreadA(threadTestA);
        ThreadB threadB = new ThreadB(threadTestA);
        threadA.start();
        threadB.start();
    }

    static class ThreadA extends Thread{
        private ThreadTestA threadTestA;


        public ThreadA(ThreadTestA threadTestA) {
            this.threadTestA = threadTestA;
        }

        public ThreadTestA getThreadTestA() {
            return threadTestA;
        }

        public void setThreadTestA(ThreadTestA threadTestA) {
            this.threadTestA = threadTestA;
        }

        @Override
        public void run() {
            threadTestA.methodA();
        }
    }


    static class ThreadB extends Thread{
        private ThreadTestA threadTestA;


        public ThreadB(ThreadTestA threadTestA) {
            this.threadTestA = threadTestA;
        }

        public ThreadTestA getThreadTestA() {
            return threadTestA;
        }

        public void setThreadTestA(ThreadTestA threadTestA) {
            this.threadTestA = threadTestA;
        }

        @Override
        public void run() {
            threadTestA.methodB();
        }
    }
}
